<template>
<section class="page page-theme reg-page">
  <header class="page-header">
    <router-link class="btn-close" to="/">
      <i class="el-icon-close"></i>
    </router-link>
    <span class="pull-right p-h-text">
      已有账户？ <router-link class="min-link" to="/login">登录</router-link>
    </span>
  </header>

  <h2 class="current-title">创建账户</h2>

  <div class="form-waper">
    <div class="select-member" v-if="form.member">
      <div class="item" :class="{'active': form.member == 'year'}">
        <div class="item-inner" @click=" form.member = 'year'">
          <p> 年会员 </p>
          <p> ￥200 - <small>节省</small>30% </p>
        </div>
      </div>
      <div class="item" :class="{'active': form.member == 'mon'}">
        <div class="item-inner" @click=" form.member = 'mon'">
          <p> 月会员 </p>
          <p> ￥25 </p>
        </div>
      </div>
    </div>

    <el-form ref="currentForm" status-icon :rules="rules" :model="form">
      <el-form-item prop="tel">
        <el-input v-model.trim="form.tel" placeholder="请输入您的手机号">
          <i slot="prefix" class="fa fa-phone-square input-ico"></i>
        </el-input>
      </el-form-item>
      <el-form-item prop="code">
        <el-input v-model.trim="form.code" placeholder="请输入手机验证码">
          <i slot="prefix" class="fa fa-shield input-ico"></i>
          <el-button slot="append" @click.native="captcha($event)" tabindex="-1">获取验证码</el-button>
        </el-input>
      </el-form-item>
      <el-form-item prop="password">
        <el-input type="password" v-model.trim="form.password" placeholder="请设置一个密码，不少于6位">
          <i slot="prefix" class="fa fa-lock input-ico"></i>
        </el-input>
      </el-form-item>
      <el-form-item>
        <el-button class="btn-block" type="primary" @click="submit">注册</el-button>
      </el-form-item>
      <span class="desc">
        注册表示您已阅读并同意 <a class="min-link" href="javascript:">《用户条款》</a>
      </span>
    </el-form>
  </div>


</section>
</template>

<script>
export default {
  name: 'RegPage',
  data () {
    return {
      form: {
        tel: '',
        code: '',
        password: '',
        member: ''
      },
      rules: {
        tel: [
          { required: true, message: '手机号不能为空', trigger: 'blur' },
          { pattern: /^1[3-9]\d{9}$/, message: '请输入正确的手机号', trigger: 'blur' }
        ],
        password: [
          { required: true, message: '密码不能为空', trigger: 'blur' },
          { min: 6, max: 32, message: '长度在 6 到 32 个字符', trigger: 'blur' }
        ],
        code: [
          { required: true, message: '验证码不能为空', trigger: 'blur' }
        ]
      }
    }
  },
  mounted() {
    this.form.member = this.$route.query.member || '';
  },
  methods: {
    submit() {
      this.$refs.currentForm.validate(valid => {
        console.log(valid);
      });
    },

    /**
     * 发送验证码
     * @param {event} e
     */
    captcha(e) {
      this.$refs.currentForm.validateField('tel', err => !err && this.$fn.captcha(e));
    }

  }
}
</script>

<style lang="less">
@import '../style/_mixin.less';

.p-h-text {
  display: inline-block;
  line-height: 36px;
  font-size: 14px;
}
.select-member {
  margin-right: -15px;
  margin-bottom: 22px;
  font-size: 0;

  .item {
    display: inline-block;
    width: 50%;
    height: 120px;
    padding-right: 15px;
    box-sizing: border-box;
    cursor: pointer;
    
    .item-inner {
      position: relative;
      height: 100%;
      padding-top: 30px;
      font-size: 20px;
      text-align: center;
      background: #eee;
      border-radius: 4px;
      box-sizing: border-box;
      transition: all .2s ease-in-out;

      &:hover {
        box-shadow: 0 6px 16px #f9f9f9;
      }
      &:active {
        transform: translate(0, 3px);
      }
      
      &::before {
        content: "";
        position: absolute;
        top: 10px;
        left: 12px;
        display: block;
        width: 24px;
        height: 24px;
        background: #fff;
        border-radius: 50%;
        color: #fff;
      }
    }

    &.active .item-inner {
      background: @theme;
      color: #fff;
      box-shadow: 0 6px 16px #9bccff;

      &::before {
        content: "\E639";
        font-family: element-icons!important;
        font-size: 27px;
        background: transparent;
        top: 2px;
        left: 11px;
      }
    }
  }
}
</style>
